package com.jiangyg.mall.authz.support.authentication.admin;

import com.jiangyg.mall.authz.constant.SecurityConstant;
import com.jiangyg.mall.core.utils.WebUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.security.web.util.matcher.RequestMatcher;

import javax.servlet.http.HttpServletRequest;

/**
 * 类描述：后台管理请求匹配
 * 请求头中包含 cid = a 时，表示为后端管理请求
 *
 * @author jiangyg
 * @date 2022-01-08
 */
public class AdminRequestMatcher implements RequestMatcher {

    private static final String value = "a";

    @Override
    public boolean matches(HttpServletRequest request) {
        final String clientTypeHeaderName = SecurityConstant.clientTypeHeaderName();
        final String client = WebUtils.attemptReadRequestArgument(clientTypeHeaderName, request);
        return StringUtils.equals(client, value);
    }

}
